package com.example.dream.learnandroid;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EditTextActivity extends AppCompatActivity {

    private static String TAG = "EditTextActivity: ";

    private EditText mEditTextUserName;
    private EditText mEditTextPassword;
    private Button mBtnLogin;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text);

        mEditTextUserName = findViewById(R.id.et_1);
        mEditTextPassword = findViewById(R.id.et_2);

        mBtnLogin = findViewById(R.id.btn_login);
        mBtnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String userName = mEditTextUserName.getText().toString();
                if(userName.isEmpty()){
                    Toast.makeText(EditTextActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
                    return;
                }

                String password = mEditTextPassword.getText().toString();
                if(password.isEmpty()){
                    Toast.makeText(EditTextActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
                    return;
                }
                Log.d(TAG, "userName " + userName + " password " + password);
                Toast.makeText(EditTextActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
            }
        });

    }
}
